package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.WcsLineBodyAbnormalMapper;
import me.zhengjie.pojo.entity.PageBean;
import me.zhengjie.pojo.entity.WcsLineBodyAbnormal;
import me.zhengjie.pojo.entity.WcsLineBodyAbnormalHistory;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class WcsLineBodyAbnormalService extends ServiceImpl<WcsLineBodyAbnormalMapper, WcsLineBodyAbnormal> implements me.zhengjie.sqlservice.WcsLineBodyAbnormalService {

    private final WcsLineBodyAbnormalMapper wcsLineBodyAbnormalMapper;

    @Override
    public boolean inertAbnormal(WcsLineBodyAbnormal wcsLineBodyAbnormal) {
        return wcsLineBodyAbnormalMapper.insert(wcsLineBodyAbnormal) >0;
    }

    @Override
    public List<WcsLineBodyAbnormal> selectAll() {
        return wcsLineBodyAbnormalMapper.selectList(null);
    }

    @Override
    public boolean delectId(Integer id) {
        return wcsLineBodyAbnormalMapper.deleteById(id) >0;
    }

    @Override
    public List<WcsLineBodyAbnormal> selectContainer(String container) {
        LambdaQueryWrapper<WcsLineBodyAbnormal> wcsLineBodyAbnormalLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsLineBodyAbnormalLambdaQueryWrapper.eq(WcsLineBodyAbnormal::getContainerCode,container)
                .orderByDesc(WcsLineBodyAbnormal::getCreateTime);
        return wcsLineBodyAbnormalMapper.selectList(wcsLineBodyAbnormalLambdaQueryWrapper);
    }

    @Override
    public PageBean Page(Integer page, Integer pageSize, String containerCode, String abnormalInformation, Integer palletId, List<LocalDateTime> times) {
        if(page==null)page=1;
        if(pageSize==null)pageSize=10;
        LocalDateTime start=null,end=null;
        if(times!=null&&times.size()==2)
        {
            start  =times.get(0);
            end  =times.get(1);
        }
        else if(times!=null&&times.size()==1)
        {
            start  =times.get(0);
        }

        PageHelper.startPage(page,pageSize);
        List<WcsLineBodyAbnormal> wcsLineBodyAbnormalHistories = wcsLineBodyAbnormalMapper.Page(page, pageSize, containerCode, abnormalInformation, palletId, start, end);

        Page<WcsLineBodyAbnormal> p=(Page<WcsLineBodyAbnormal>) wcsLineBodyAbnormalHistories;
        PageBean pageBean = new PageBean(p.getTotal(),wcsLineBodyAbnormalHistories);

        return pageBean;
    }

//    @Override
//    public List<WcsLineBodyAbnormal> selectByContainerCode(String containerCode) {
//        LambdaQueryWrapper<WcsLineBodyAbnormal> wcsLineBodyAbnormalLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        wcsLineBodyAbnormalLambdaQueryWrapper.eq(WcsLineBodyAbnormal::getContainerCode,containerCode);
//        return wcsLineBodyAbnormalMapper.selectList(wcsLineBodyAbnormalLambdaQueryWrapper);
//
//
//
//    }
//
//    @Override
//    public List<WcsLineBodyAbnormal> selectByAbnotmalInformation(String information) {
//        LambdaQueryWrapper<WcsLineBodyAbnormal> wcsLineBodyAbnormalLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        wcsLineBodyAbnormalLambdaQueryWrapper.eq(WcsLineBodyAbnormal::getAbnormalInformation,information);
//        return wcsLineBodyAbnormalMapper.selectList(wcsLineBodyAbnormalLambdaQueryWrapper);
//
//
//    }
//
//    @Override
//    public List<WcsLineBodyAbnormal> selectByPalletId(Integer palletId) {
//        LambdaQueryWrapper<WcsLineBodyAbnormal> wcsLineBodyAbnormalLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        wcsLineBodyAbnormalLambdaQueryWrapper.eq(WcsLineBodyAbnormal::getPalletId,palletId);
//        return wcsLineBodyAbnormalMapper.selectList(wcsLineBodyAbnormalLambdaQueryWrapper);
//    }
//
//    @Override
//    public List<WcsLineBodyAbnormal> selectByCreateTime(List<LocalDateTime>times) {
//
//           LocalDateTime start  =times.get(0);
//           LocalDateTime end  =times.get(1);
//        LambdaQueryWrapper<WcsLineBodyAbnormal> wcsLineBodyAbnormalLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        wcsLineBodyAbnormalLambdaQueryWrapper.between(WcsLineBodyAbnormal::getCreateTime,start,end);
//        return wcsLineBodyAbnormalMapper.selectList(wcsLineBodyAbnormalLambdaQueryWrapper);
//    }
}
